package com.ruoyi.teacher.material.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.teacher.material.domain.Material;
import com.ruoyi.teacher.material.mapper.MaterialMapper;
import com.ruoyi.teacher.material.service.IMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 教学素材Service业务层处理
 *
 * @author duanxinli
 * @date 2023-11-07
 */
@Service
public class MaterialServiceImpl implements IMaterialService {
    @Autowired
    private MaterialMapper materialMapper;

    /**
     * 查询教学素材
     *
     * @param id 教学素材主键
     * @return 教学素材
     */
    @Override
    public Material selectMaterialById(String id) {
        return materialMapper.selectMaterialById(id);
    }

    /**
     * 查询教学素材列表
     *
     * @param material 教学素材
     * @return 教学素材
     */
    @Override
    public List<Material> selectMaterialList(Material material) {
        return materialMapper.selectMaterialList(material);
    }

    /**
     * 新增教学素材
     *
     * @param material 教学素材
     * @return 结果
     */
    @Override
    public int insertMaterial(Material material) {
        material.setId(IdUtils.fastUUID());
        material.setCreateDate(DateUtils.getNowDate());
        String username = SecurityUtils.getUsername();
        material.setCreateBy(username);
        return materialMapper.insertMaterial(material);
    }

    /**
     * 修改教学素材
     *
     * @param material 教学素材
     * @return 结果
     */
    @Override
    public int updateMaterial(Material material) {
        return materialMapper.updateMaterial(material);
    }

    /**
     * 批量删除教学素材
     *
     * @param ids 需要删除的教学素材主键
     * @return 结果
     */
    @Override
    public int deleteMaterialByIds(String[] ids) {
        return materialMapper.deleteMaterialByIds(ids);
    }

    /**
     * 删除教学素材信息
     *
     * @param id 教学素材主键
     * @return 结果
     */
    @Override
    public int deleteMaterialById(String id) {
        return materialMapper.deleteMaterialById(id);
    }
}
